import { PRIORITY_VIEW } from "../../../Core/CoreDefine";
import { GCtrl } from "../../../Core/GCtrl";
import { GListView } from "../../../Core/GView/GListView";
import GPage from "../../../Core/GView/GPage";
import GPageView from "../../../Core/GView/GPageView";
import GViewBase from "../../../Core/GView/GViewBase";
import { CMsg, ComonTip, LISTENTTYPE } from "../../Common/Define";
import { VIEW_ID } from "../../Common/UI";
import { Res } from "../../Common/UIResources";
import GameMgr from "../../Logic/GameMgr";
import { IHeroSort, SHeroSort } from '../../Logic/HeroMgr';
import TopUiItem from "../Common/TopUiItem";
import HeroCardItem from "./HeroCardItem";

const { ccclass, property, menu, executeInEditMode } = cc._decorator;
@ccclass @menu('View/Hero/DianjiangView')

export default class DianjiangView extends  GViewBase {


    @property({type: cc.Node,tooltip: "武将图片"})  tog1Node: cc.Node = null;

    @property({type: cc.Node,tooltip: "武将遣散"})  tog2Node: cc.Node = null;

    @property({type: cc.Node,tooltip: "武将重生"})  tog3Node: cc.Node = null;

    @property({type: cc.Node,tooltip: "武将回退"})  tog4Node: cc.Node = null;

    @property({type: cc.Node,tooltip: "品质多选"})  qualityTog: cc.Node = null;

    private _listView: GListView = null;
    private _curListIndex: number = 0;

    private _curPageIndex: number = 0;      //分页

    onGLoad() {
        this.refresh();
        this.addHang();
    }

    public addHang() {
        /**顶部UI */
        this.addGChild<TopUiItem>(Res.prefab.item.topUiItem, (comp: TopUiItem) => {
            //comp.node.parent = GameMgr.uiMgr.uiRoot;
            comp.node.parent = this.bgImage.node;
            let winSize = cc.winSize;
            // comp.node.setPosition(cc.v2(-winSize.width / 2, winSize.height / 2));
            comp.setModeType(1, "点将台"); 
            comp.node.setPosition(cc.v2(-winSize.width / 370, winSize.height / 2.16));
            // let hang = comp.addComponent(hangPage);
            // hang.addListenPage([VIEW_ID.home, VIEW_ID.storePage, VIEW_ID.heroPage, VIEW_ID.squadPage, VIEW_ID.recruitPage],
            //     [VIEW_ID.officer, VIEW_ID.levelCtrl, VIEW_ID.blessCtrl, VIEW_ID.towerCtrl, VIEW_ID.fightLayer, VIEW_ID.detailsCtrl]);
        });
    }

    refresh(){
        this.tog1Node.active = this._curPageIndex==0;

        this.tog2Node.active = this._curPageIndex==1;

        this.tog3Node.active = this._curPageIndex==2;

        this.tog4Node.active = this._curPageIndex==3;
    }
    /**武将品质切换*/
    protected btnOnce(CustomEventData, index) {
        this._curListIndex = Number(CustomEventData.node._name);
        GCtrl.ES.emit(CMsg.client.home.onBattleItem, -1);
    }

    /**0 武将，1图鉴，2编队 */
    protected btnPage(CustomEventData, index) {
        this._curPageIndex = Number(CustomEventData.node._name);
        //GCtrl.ES.emit(CMsg.client.home.onBattleItem, -1);
        // this.dealWithData();

        this.refresh();
    }

    /**初始每个卡牌 */
    public onItemSetter(item: HeroCardItem, data: SHeroDataRaw | IHeroData, index: number) {
        item.init(data, index, LISTENTTYPE.listent2);
    }

    onClickHanlder(event:any, str:string){
        if (str == "tog1"){
            this.refresh();
        }
        else if (event.target._name == "ruleBtn"){
            // let til =  this.selectTog == 1 ? "闯关进度" : this.selectTog == 2 ? "战将进度" : "竞技场进度"
            GameMgr.jumpToMgr.jumpGoTo(VIEW_ID.comonTipView, ComonTip.ruleBtn);
        }
    }
}